<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /* 
            需求：完成随机点名
            var names = ['张三','李四','王五','赵六','孙七'];
            实际场景：从10名用户中抽奖
        */

        //如何获取随机数
       //随机数区间：0.0000000000000000 -> 0.999999999999999999
       console.log(Math.random());
       console.log(Math.random());
       console.log(Math.random());
       console.log(Math.random());

       var names = ['张三','李四','王五','赵六','孙七'];

       function getRandomName(names){
            return names[getRandomInt(names.length)];
       }

       function getRandomInt(max){
            return Math.floor(Math.random()*max);
       }

       
        var count = 1;
        while (count <= 20) {
            console.log(getRandomName(names));
            count++;
        }

        /* 
            得到一个两数之间的随机数
            10 - 20 结果就是 10-19
            10 - 21 结果就是 10-20
        */
        function getRandomArbitrary(min, max){
            return Math.floor(Math.random()*(max-min)+min);
        }

        var count2 = 1;
        while (count2 <= 30) {
            console.log(Math.floor(getRandomArbitrary(10,21)));
            count2++;
       }
    </script>
</head>
<body>
    
</body>
</html>